package com.CMS.server;

import java.util.List;

import com.CMS.client.AdministrationService;
import com.CMS.server.dao.AdministrationDao;
import com.CMS.server.domain.Administration;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class RpcAdministration extends RemoteServiceServlet implements AdministrationService{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6347146658861759932L;

	@Override
	public void Update(String mail, String telephone, String razon,
			String direccion, String url) {
		AdministrationDao dao = new AdministrationDao();
		List<Administration> lista = dao.getAll();
		Administration a = null;
		if(lista == null){
			a = new Administration();			
		}
		else{
			a = dao.getEntity(lista.get(0).getId());			
		}
		a.setMail(mail);
		a.setTelephone(telephone);
		a.setRazonSocial(razon);
		a.setDireccion(direccion);
		a.setUrl(url);
		if(lista == null)
			dao.createEntity(a);
		else
			dao.updateEntity(a);
	}

	@Override
	public Administration get() {
		AdministrationDao dao = new AdministrationDao();
		return dao.getAll().get(0);
	}

}
